<template>
<view>
<!--pages/productDetail/index.wxml-->


<view class="container">

<view class="SwiperContainer">
    <swiper class="SwiperIndex" autoplay="true" interval="5000" duration="500" @change="swiperChange">
      <block v-for="(item, swiper) in productData.images" :key="swiper" style="border-radius: 20rpx">
        <swiper-item :data-imageUrl="productData.images" :data-index="index" @tap="lookBigImage" style="border-radius: 20rpx">
          <image mode="aspectFit" :src="item.imagePath + '?x-oss-process=style/normal'" style="border-radius: 20rpx"></image>
        </swiper-item> 
      </block>
    </swiper>
    <view class="swiperItemIndex">{{swiperIndex}}/{{totalImg}}</view>
  </view>  
 
  <view class="ProductDetailInfoContainer" style="position: relative;">
    <view class="pintuan_tip">
      <view class="pintuan_tip_price" :style="'background:' + setting.platformSetting.defaultColor">积分兑换</view>
      <view class="triangle_border_left" :style="'border-color: transparent transparent transparent ' + setting.platformSetting.defaultColor + ';'"></view>
    </view>
    <view class="InfoPrice_content">
       <view class="InfoPrice">
          <view class="p1 price_font">
          <!-- ￥{{publicFun.toFix(productData.productInfo.price*productData.productInfo.promotionBean.pintuanStrategy.priceZhekou)}}计算数据 -->
            <text class="jifen">
              {{jifenNum}}
            </text>
            <text>积分</text>
            <text v-if="productData.productInfo.unitShow" style="color:#bbb;font-size:24rpx;margin-left:4rpx;letter-spacing:4rpx;line-height:30rpx;">
              /{{productData.productInfo.unitShow}}
            </text>
          </view>
          <view class="product_stock"><text>仅剩{{jifenCount}}件</text></view>
       </view>
       <view class="share_product" @tap="showPoster">
       </view>
    </view>
    <view class="InfoName">{{productData.productInfo.name}}</view>
    <block v-if="!!productData.productInfo.description">
      <view class="InfoSubName ">·{{productData.productInfo.description}}</view>
    </block>
  </view>
   <block v-if="clientNo=='tunzai'">
    <view class="tap_title">
        <view class="tap_title_left">
          <view class="tap_title_item"><view class="dot"></view><text class="tap_title_font">正品保证</text></view>
          <view class="tap_title_item"><view class="dot"></view><text class="tap_title_font">永久包邮</text></view>
          <view class="tap_title_item"><view class="dot"></view><text class="tap_title_font">一对一专属售后</text></view>
        </view>
        <view class="tap_title_right">
          <view class="dot_no"></view>
          <view class="dot_no"></view>
          <view class="dot_no"></view>
        </view>
      </view>
    </block>
    <block v-else>
      <block v-if="targs.length!=0">
        <view class="tap_title">
        <view class="tap_title_left">
          <scroll-view style="width:100%;overflow:hidden;white-space:nowrap" scroll-x>
            <view style="display:inline-block" v-for="(item, index) in targs" :key="index">
              <view class="tap_title_item">
                <view class="dot" :style="'background:' + setting.platformSetting.defaultColor+55 + ';border:2rpx solid ' + setting.platformSetting.defaultColor+22 + ';box-shadow:0px 4rpx 14rpx 0px ' + setting.platformSetting.defaultColor+22 + ',0px 4rpx 6rpx 0rpx ' + setting.platformSetting.defaultColor+11 + ';'"></view>
              <text class="tap_title_font">{{item}}</text>
              </view>
            </view>
          </scroll-view>
        </view>
        <!-- <view class='tap_title_right'>
          <view class='dot_no'></view>
          <view class='dot_no'></view>
          <view class='dot_no'></view>
        </view> -->
      </view>
      </block>
    </block>
    <!-- 导航 -->
    <view class="navigation_to_map" v-if="positionState">
      <view class="navigation_addr">
        <image class="navigation_addr_img" src="https://image1.sansancloud.com/xianhua/2018_9/13/17/57/21_219.jpg?x-oss-process=style/preview_120"></image>
        <text class="navigation_addr_value">{{productData.productInfo.location}}</text>
      </view>
      <view class="navigation_button" :style="'background:' + setting.platformSetting.defaultColor" @tap="clickCatch">
        <image class="navigation_button_img" src="https://image1.sansancloud.com/xianhua/2018_9/13/21/22/3_772.jpg?x-oss-process=style/preview_120"></image>
        <text class="navigation_button_value">位置</text>
      </view>
    </view>

    <view v-if="measuresState">
      <block v-if="haveMeasuresState">
        <view class="specifications" data-way="select" @tap="readyPay2">
          <text class="have_select">已选择</text>
          <view class="value">
            <text class="value_item" v-for="(item, index) in selectTypeData" :key="index">{{item.value}}</text>
          </view>
        </view>
      </block>
      <block v-else>
        <view class="specifications" data-way="select" @tap="readyPay2">
          <text class="no_select" :style="'color:' + setting.platformSetting.defaultColor">请选择规格</text>
        </view>
      </block>
    </view>

    <view class="product_introduce">
      <view class="product_introduce_short" v-if="attrsState">
        <text class="product_introduce_title">商品介绍</text>
        <view class="product_introduce_item" v-for="(item, index) in productData.attrs" :key="index">
            <text class="product_introduce_item_name">{{item.attributeName}}</text>
            <text class="product_introduce_item_vaule">{{item.attributeValue}}</text>
        </view>
      </view>
    </view>
    <!-- 首页组件-私有产品详情装饰-->
    <!-- <view style='margin-top:20rpx;'>
     <component-customPage data="{{sendProductData}}" wx:if="{{sendProductData}}"></component-customPage> 
    </view> -->
    <!-- 富文本 -->
    <view class="product_main_info" v-if="productData.description.description!=''&&productData.description.description!='<p><br></p>'">
      <text>图文详情</text>
    </view>
    <view class="tab_detail_container" v-if="productData.description.description!=''&&productData.description.description!='<p><br></p>'">
       <view class="wxParseHtmlContainer">
		  <rich-text-component :receiveData="articleJsonData" v-if="articleJsonData"></rich-text-component>
       </view>
    </view>

    <!-- <view class='price_explain'>
      <text class='price_explain_title'>价格说明</text>
      <view class='price_explain_content'>店铺中展示的中间未划横线价格为该店铺的销售价，该价格是交易成交价，是您最终决定是否购买商品的依据。店铺展示的中间划横线价格(显示如¥1000)为参考价，采集自品牌专柜标价、商品吊牌价或由品牌供应商提供的正品零售价由于地区、时间的差异性和市场行情波动，品牌专柜标价、商品吊牌价可能会与您购物时展示的不一致。该价格仅供您参考。</view>
    </view> -->

 <!-- 首页组件-公共产品详情装饰-->
 <custom-page-index-component :receiveData="sendIndexData" v-if="sendIndexData"></custom-page-index-component> 
</view>


<!-- 底部按钮们 -->
<view class="bottomHeight"></view>
<view class="product_detail_bottom_container">
 <view  class='left_bottom' :data-itemId="productData.productInfo.productId" @tap="toIndex">
   <image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_11/20/14/38/47_682.jpg?x-oss-process=style/preview_120"></image>
   <text style="font-size:22rpx;color:#aaa">首页</text>
  </view> 
  <view class="left_bottom" @tap="toCart" v-if="!productData.productInfo.preOrderCustomFormId">
    <view class="cartNumber" :style="'background:' + color">{{countGood}}</view>
    <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_11/20/14/39/19_841.jpg?x-oss-process=style/preview_120"></image>
    <text style="font-size:22rpx;color:#aaa">购物车</text>
  </view>
  <view class="w_540 right_bottom bynow font_08" @click.stop="buyGoods" :style="'background-image:linear-gradient(to right,' + secondColor + ',' + color + ');box-shadow:0px 0px 6px 0px ' + color + ';'">
    <text>立即兑换</text>
  </view>
</view>

<posters-component :proId="proId" :shopId="shopId" :ewmImgUrl="qrCodeUrl" v-if="posterState" @closePoaster="getChilrenPoster"></posters-component> 
<pintuan-component :pintuanParam="pintuanParam" v-if="pintuanPopupState" @closePintuan="getChilrenPintuan" @goPintuan="readyPay2"></pintuan-component> 
<measure-card-component v-if='showCount' :showCount="showCount" :pintuanParams="pintuanParams" :productData='productData' :byNowParams="byNowParams" :bindway="bindway" @closeCard="getCloseCardFun"></measure-card-component>

 <!-- <component is="measure_card2" :setting="minCount" :focusData="productData.productInfo" :measures="productData.measures" :byNowParams="byNowParams" :measurementJson="measurementJson" :type="bindway"></component> -->
</view>
</template>

<script>

import publicFun from '../../wxcomponents/public/publicFun.wxs'
var WxParse = require('../../wxcomponents/wxParse/wxParse.js')
// import posters from "../../view/partials/canvas/index";
// import time from "../../view/partials/time/time";
// import pintuan from "../../view/partials/pintuan_popup/index";
// import componentCustompage from "../../view/partials/custom_page/index";

export default {
  data() {
    return {
      setting: null,
      // setting 
      productData: null,
      // 商品数据 
      jifenNum: 0,
      jifenCount: 0,
      jifenId: 0,
      cart: null,
      countGood: 0,
      sysWidth: 320,
      //图片大小
      showCount: false,
      saleStrategyState: false,
      measuresState: false,
      positionState: false,
      attrsState: false,
      targs: [],
      posterState: false,
      pintuanPopupState: false,
      proId: '',
      shopId: '',
      bindway: 'cart',
      //点击的是加入购物车或者立即购买
      showState: 0,
      commitList: [],
      measurementJson: null,
      qrCodeUrl: "",
      haveMeasuresState: false,
      selectTypeData: null,
      swiperIndex: 1,
      totalImg: 0,
      pintuanId: 0,
      pintuanState: false,
      promotionState: false,
      pintuanListData: [],
      color: '',
      secondColor: "",
      clientNo: '',
      minCount: '1',
      sendIndexData: null,
      buyType: 'normal',
	  articleJsonData:'',
      byNowParams: {
        productId: '',
        itemCount: 1,
        shopId: '',
        cartesianId: '0',
        fromSource: 'mini',
        orderType: ''
      },
      pintuanParams: {
        pintuanCreateType: 0,
        pintuanRecordId: 0
      },
      dataFOr_getData: {
        id: '',
        addShopId: ''
      },
      pintuanParam: "",
      visiblePintuanNum: 0,
      showGuigeType: false,
      article_article: ""
    };
  },

  props: {},
  onError: function (options) {
    console.log("on error!!!");
  },
  onLoad: function (options) {
    this.publicFun = publicFun;
    console.log('--------product----------', options);
    let that = this;

    if (options.type == 'jifen') {
      that.setData({
        buyType: options.type,
        jifenNum: options.jifenNum || 0,
        jifenCount: options.jifenCount || 0,
        jifenId: options.jifenId || 0
      });
    }

    console.log('--------buyType----------', that.buyType);
    that.setData({
      sysWidth: getApp().globalData.sysWidth,
      proId: options.id || options.productId,
      shopId: options.addShopId || 236,
      clientNo: getApp().globalData.clientNo,
      color: getApp().globalData.setting.platformSetting.defaultColor,
      secondColor: getApp().globalData.setting.platformSetting.secondColor
    });
    let sendIndexData = JSON.stringify({ title: 'noTitle', url: "productdetail", params: { pageObjectId: options.id || options.productId} })
    that.setData({ sendIndexData: sendIndexData })
    let sendProductData = JSON.stringify({ title: 'noTitle', url: "product_detail_" + (options.id || options.productId) })
    that.setData({ sendProductData: sendProductData })

    console.log("商品id和店铺id", options);
    that.dataFOr_getData.id = options.id || options.productId;
    that.dataFOr_getData.addShopId = options.addShopId || 236;
    that.setData({
      dataFOr_getData: that.dataFOr_getData
    });
    that.getData(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareTimeline:function(){
    return this.shareFun();
  },
  onShareAppMessage: function (res) {
    console.log(res);
    return this.shareFun();
    
  },
  methods: {
    shareFun:function(){
        let that = this;
        let params = that.dataFOr_getData;
        let productItem = that.productData.productInfo;
        
        if (!productItem.brandName || productItem.brandName == "") {
          productItem.brandName = "";
        }
        
        ;
        let shareName = '活动价：￥' + productItem.price + '(原价：￥' + productItem.tagPrice + ')' + productItem.brandName + productItem.name;
        console.log('params:', params, that.productData);
        return getApp().globalData.shareForFx2('productDetail', shareName, params);
    },
    /*轮播图下标*/
    swiperChange: function (e) {
      this.setData({
        swiperIndex: e.detail.current + 1
      });
    },

    // 关闭海报
    getChilrenPoster(e) {
      let that = this;
      that.setData({
        posterState: false
      });
    },

    getChilrenPintuan(e) {
      let that = this;
      that.setData({
        pintuanPopupState: false
      });
    },

    showPintuan: function () {
      console.log('=======');
      let that = this;
      that.setData({
        pintuanPopupState: true
      });
    },
    showPoster: function () {
      console.log('===showPoster====', getApp().globalData.clientNo);
      let that = this;
      this.getQrCode();
      that.setData({
        posterState: true
      });
    },
    toIndex: function () {
      getApp().globalData.toIndex();
    },
    posterStateFun: function (state) {
      console.log('====state====', state);
      this.setData({
        posterState: true
      });
    },
    lookBigImage: function (e) {
      console.log("111111111", e.currentTarget.dataset);
      let imgSrc = e.currentTarget.dataset.imageurl;
      let imgArray = [];
      let index = e.currentTarget.dataset.index;
      let PostImageSrc = [];
      console.log(imgSrc);

      for (let i = 0; i < imgSrc.length; i++) {
        imgArray.push(imgSrc[i].imagePath);
        PostImageSrc.push(imgSrc[i].imagePath.replace(/http/, "https"));
      } // let PostImageSrc = imgSrc


      console.log(PostImageSrc);

      if (!imgSrc) {
        return;
      } // let urls = []
      // urls.push(imgSrc)


      wx.previewImage({
        current: imgArray[index],
        // 当前显示图片的http链接
        urls: imgArray // 需要预览的图片http链接列表

      });
    },
    showCouponState: function (e) {
      var index = e.currentTarget.dataset.id;
      this.setData({
        showState: index
      });
    },
    aaaaa: function (e) {
      console.log("hello");
      getApp().globalData.linkEvent("product_detail_9218.html");
    },

    /* 删除收藏 */
    removeFavourite: function (e) {
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var postData = {
        itemId: '',
        favoriteType: '1'
      };
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      var customIndex = getApp().globalData.AddClientUrl("/remove_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 0;
            that.setData({
              productData: productData
            });
            console.log('000---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },

    /* 加入收藏 */
    addToFavourite: function (e) {
      var that = this;
      var postData = {
        itemId: '',
        favoriteType: '1'
      }; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      console.log(postData);
      var customIndex = getApp().globalData.AddClientUrl("/add_to_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 1;
            that.setData({
              productData: productData
            });
            console.log('111---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },

    /* 查看图文详情   -- 已禁用 */
    lookDerection: function (e) {
      var images = e.currentTarget.dataset.derection;
      var sentMessage = "";

      for (let i = 0; i < images.length; i++) {
        sentMessage += "&" + i + "=" + images[i];
      }

      sentMessage = sentMessage.substring(1);
      console.log(sentMessage);
      wx.navigateTo({
        url: '/pages/productDetail_derection/index?' + sentMessage
      });
    },
    ChangeParam: function (params) {
      var returnParam = "";

      for (let i in params) {
        returnParam += "&" + i + "=" + params[i];
      }

      return returnParam;
    },

    /* dadianhua */
    callShop: function () {
      if (this.setting) {
        wx.makePhoneCall({
          phoneNumber: this.setting.platformSetting.defaultShopBean.telno //仅为示例，并非真实的电话号码

        });
      }
    },
    toCart: function () {
      console.warn("cart"); // let url ="shopping_car_list_new.html"

      wx.navigateTo({
        url: '/pages/shopping_car_list_new/index'
      }); // app.linkEvent(url)
    },

    /* 找到购物车里面的内容 */
    findInCart: function (data) {
      var cart = null;
      this.postParams(data);
    },
    readyPay: function (e) {
      this.setData({
        showCount: true
      });
      let info = e.currentTarget.dataset.item;
      this.byNowParams.productId = info.productId;
      this.byNowParams.shopId = info.belongShopId;
      this.byNowParams.orderType = 0;
      this.setData({
        byNowParams: this.byNowParams
      });
    },
    readyPay2: function (e) {
      console.log('====e=====', e);

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      if (this.productData.productInfo.promotionBean && this.productData.productInfo.promotionBean.promotionStatus == 2) {
        console.log('活动已结束！');
        wx.showToast({
          title: '活动已结束！',
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
        return;
      }

      let productData = this.productData;
      let way;
      let pintuanRecordId;
      console.log(productData);

      if (e.currentTarget.dataset.way) {
        way = e.currentTarget.dataset.way;
        pintuanRecordId = e.currentTarget.dataset.pintuanid;
      } else {
        way = e.detail.data.way;
        pintuanRecordId = e.detail.data.pintuanid;
      }

      this.setData({
        bindway: way
      });
      console.log('====q=====', this.bindway);
      let info = productData.productInfo;
      this.byNowParams.productId = info.productId;
      this.byNowParams.shopId = info.belongShopId;
      this.setData({
        byNowParams: this.byNowParams
      });

      if (way == 'cart') {
        if (productData.measures.length == 0) {
          this.addtocart();
        } else {
          this.setData({
            showCount: true
          });
          this.byNowParams.orderType = 0;
          this.setData({
            byNowParams: this.byNowParams
          });
          this.chooseMeasureItem();
        }
      } else if (way == 'pintuanOne') {
        //单独购买
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 0;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'pintuanMore') {
        //参加拼团
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 1;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'addPintuan') {
        //发起拼单
        this.setData({
          showCount: true
        });
        this.setData({
          pintuanPopupState: false
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 2;
        this.pintuanParams.pintuanRecordId = pintuanRecordId;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'select') {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        this.chooseMeasureItem();
      } else {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        this.chooseMeasureItem();
      }
    },
    closeZhezhao: function () {
      this.setData({
        showCount: false
      });
    },
    subNum: function () {
      if (this.measurementJson.id) {
        this.setData({
          minCount: this.measurementJson.minSaleCount
        });
      } else {
        this.setData({
          minCount: 1
        });
      }

      if (this.byNowParams.itemCount == this.minCount) {
        return;
      }

      this.byNowParams.itemCount--;
      this.setData({
        byNowParams: this.byNowParams
      });
    },
    addNum: function () {
      this.byNowParams.itemCount++;
      this.setData({
        byNowParams: this.byNowParams
      });
    },

    /* 立即购买 */
    buyNow: function (e) {
      if (!getApp().globalData.checkShopOpenTime()) {
        return;
      }

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      let bindway;

      if (e.currentTarget.dataset.way) {
        bindway = e.currentTarget.dataset.way;
      } else {
        bindway = this.bindway;
      }

      console.log('=======bindway======', bindway);

      if (bindway == 'cart') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.addtocart();
      } else if (bindway == 'pintuanOne') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else if (bindway == 'pintuanMore') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else if (bindway == 'addPintuan') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else {
        console.log('-----------buyNow----------');
        this.createOrder22(this.byNowParams);
      }
    },

    /* 创建订单 */
    createOrder22: function (o) {
      console.log('========createOrder22======', o);
      let that = this;
      let productInfo = that.productData.productInfo;
      let params = Object.assign({}, params, that.byNowParams, that.pintuanParams); // wx.showLoading({
      //   title: 'loading',
      //   mask: true
      // })

      getApp().globalData.showToastLoading('loading', true);
      getApp().globalData.createOrder(that.byNowParams, that.pintuanParams);
    },

    /* 加入購物車 */
    addtocart: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var params = {
        cartesianId: '',
        productId: '',
        shopId: '',
        count: '',
        type: ''
      };

      if (this.productData.measures.length == 0) {
        params.cartesianId = '0';
      } else {
        params.cartesianId = this.measurementJson.id;
      }

      params.productId = this.productData.productInfo.productId;
      params.shopId = this.productData.productInfo.belongShopBean.id;
      params.count = this.byNowParams.itemCount;
      params.type = 'add';
      console.log('===postParams=====', params);
      this.postParams(params);
    },
    postParams: function (data) {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('---------------change_shopping_car_item-----------------');
          console.log(res.data);
          wx.hideLoading();

          if (that.bindway == 'cart') {
            that.setData({
              showCount: false
            });
          }

          if (data.productId == 0) {
            console.log('购物车里面的商品数量');
            that.setData({
              countGood: res.data.totalCarItemCount
            });
          } else {
            if (res.data.productId && res.data.productId != 0) {
              if (data.count == 0) {
                console.log('通过加入购物车来确定购物车里面的商品数量');
              } else {
                wx.showToast({
                  title: '加入购物车成功'
                });
              }

              if (!!res.data.totalCarItemCount || res.data.totalCarItemCount == 0) {
                that.setData({
                  countGood: res.data.totalCarItemCount
                });
              }
            } else {
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 2000
              });
            }
          }
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    getPintuanData: function (productId, promotionId) {
      let that = this;
      let data = {
        status: 1,
        productId: productId,
        promotionId: promotionId
      };
      that.setData({
        pintuanParam: data
      });
      var pintuanUrl = getApp().globalData.AddClientUrl("/wx_find_pintuan_records.html", data, 'post');
      wx.request({
        url: pintuanUrl.url,
        data: pintuanUrl.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            pintuanListData: res.data.relateObj.result
          });

          if (that.pintuanListData.length == 1) {
            that.setData({
              visiblePintuanNum: 1
            });
          } else {
            that.setData({
              visiblePintuanNum: 2
            });
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    getData: function (options) {
      let param = {};
      let that = this;

      if (!options) {
        param = that.dataFOr_getData;
      } else {
        param = options;
      } // wx.showLoading({
      //   title: 'loading'
      // })


      getApp().globalData.showToastLoading('loading', true);
      console.log('==param===', param);
      let postParam = {};
      postParam.productId = param.id || param.productId;
      postParam.addShopId = param.addShopId || 236;
      let customIndex = getApp().globalData.AddClientUrl("/product_detail.html", postParam);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res);

          if (res.data.productInfo.errcode == -1) {
            wx.showToast({
              title: res.data.productInfo.relateObj,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
            return;
          }

          that.setData({
            pintuanState: false
          });
          console.log('--------------getData-------------');
          res.data.productInfo.promotion = Number(res.data.productInfo.promotion);

          if (res.data.productInfo && res.data.productInfo.promotionBean) {
            that.setData({
              promotionState: true
            });

            if (res.data.productInfo.promotionBean.promotionStatus == 2) {
              that.setData({
                color: '#888',
                secondColor: '#fff'
              });
            }

            if (res.data.productInfo.promotionBean.pintuanStrategy && res.data.productInfo.promotionBean.pintuanStrategy.id) {
              that.setData({
                pintuanState: true
              });
              that.getPintuanData(res.data.productInfo.productId, res.data.productInfo.promotionBean.id); //获取拼团人员的数据
            }
          }

          that.setData({
            productData: res.data
          });

          if (res.data.images) {
            that.setData({
              totalImg: res.data.images.length
            });
          }

          if (res.data.productInfo && res.data.productInfo.tags) {
            let tagsStr = res.data.productInfo.tags;
            let tagsStr2 = tagsStr.replace(/\[/g, '');
            let tagArr = tagsStr2.split(']');
            tagArr.length--;
            that.setData({
              targs: tagArr
            });
            console.log('targs', that.targs);
          }
          if (res.data.description && res.data.description.description) {
          			let articleJsonData=res.data.description.description;
          			that.setData({
          			  articleJsonData: {data:{jsonData:{content:articleJsonData}}}
          			});
            console.log('====articleJsonData====', that.articleJsonData);
          }
          // if (res.data.description && res.data.description.description) {
          //   //WxParse.wxParse('article', 'html', res.data.description.description, that, 10)
          //   setTimeout(function () {
          //     that.article_article = res.data.description.description;
          //   });
          //   console.log('====article====', that.article);
          // }

          if (res.data.productInfo.saleStrategy && res.data.productInfo.saleStrategy != 0) {
            that.setData({
              saleStrategyState: true
            });
            console.log('====saleStrategyState====', that.saleStrategyState);
          }

          if (res.data.measuresState && res.data.measuresState.length != 0) {
            that.setData({
              measuresState: true
            });
            console.log('====measuresState====', that.measuresState);
          }

          if (res.data.productInfo.latitude && res.data.productInfo.latitude != 0) {
            that.setData({
              positionState: true
            });
            console.log('====positionState====', that.positionState);
          }

          if (res.data.attrs && res.data.attrs.length != 0) {
            that.setData({
              attrsState: true
            });
            console.log('====attrsState====', that.attrsState);
          }

          if (!!res.data.productInfo) {
            let info = res.data.productInfo;
            let postPatam = {}; //var paramStr = 'page=1&productId=' + info.productId+'&shopId=' + info.belongShopId

            postPatam.page = 1;
            postPatam.productId = info.productId;
            postPatam.shopId = info.belongShopId; // that.getCommitData(postPatam)

            that.getCart();
          }

          console.log('productData', that.productData);
        },
        fail: function (res) {
          console.log("====fail=====");
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    // 兑换商品
    buyGoods: function (e) {
      var that = this;
      console.log(e);
      wx.showModal({
        title: '提示',
        content: '确定兑换商品',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
            that.exchange(that.jifenId);
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      });
    },
    //兑换
    exchange: function (id) {
      console.log("======a=======", id);
      var that = this; // 判断是否已经兑换过

      if (that.jifenCount <= 0) {
        wx.showToast({
          title: "超出兑换上限",
          image: '/wxcomponents/images/icons/tip.png',
          duration: 2000
        });
      } else {
        let exchange = {
          jifenItemId: id,
          fromSource: "wx"
        };
        let menDianYangShi = getApp().globalData.AddClientUrl("/jifen_exchange_phone_json.html", exchange, 'get');
        wx.request({
          url: menDianYangShi.url,
          data: menDianYangShi.params,
          header: getApp().globalData.headerPost,
          method: 'get',
          success: function (res) {
            console.log("======a=======", res);

            if (res.data.errcode == "-1") {
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 2000
              });
              console.log(res.data.errMsg);
            } else {
              wx.showToast({
                title: "兑换成功",
                image: '/wxcomponents/images/icons/targ.png',
                duration: 2000
              }); // 兑换成功后次数减少

              that.lookMore(res.data.relateObj.orderNo);
            }
          }
        });
      }
    },
    lookMore: function (orderNo) {
      console.log(orderNo);
      let url = 'order_detail.html?orderNo=' + orderNo;
      getApp().globalData.linkEvent(url);
    },
    getCart: function () {
      var params = {};
      params.productId = 0;
      params.count = 0;
      params.type = 'add';
      this.postParams(params);
    },
    //提交规格产品
    submitMeasure: function (id) {
      var that = this;
      let focusProduct = this.MeasureItem;
      let measurementJson = this.measurementJson;
      let data = {};
      data.cartesianId = measurementJson.id;
      data.productId = focusProduct.id;
      data.shopId = focusProduct.belongShopId;
      data.count = 1;
      data.type = 'add';
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            showGuigeType: false
          });
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    //获取规格价格参数
    get_measure_cartesionFun: function () {
      console.log('get_measure_cartesion');
      this.setData({
        measurementJson: {
          waitDataState: false
        }
      });
      let productId = this.productData.productInfo.productId;
      let postStr = '';

      if (this.MeasureParams.length == 0) {
        this.byNowParams.cartesianId = '0';
        this.setData({
          measurementJson: {
            waitDataState: true
          }
        }); //没有规格时 不需要等待请求

        return;
      }

      for (let i = 0; i < this.MeasureParams.length; i++) {
        postStr += this.MeasureParams[i].value + ',';
      }

      let param = {};
      param.productId = productId;
      param.measureIds = postStr;
      console.log(postStr);
      let customIndex = getApp().globalData.AddClientUrl("/get_measure_cartesion.html", param);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          that.byNowParams.cartesianId = res.data.id;
          that.setData({
            measurementJson: res.data
          });
          that.measurementJson.waitDataState = true;
          that.setData({
            measurementJson: that.measurementJson
          });
          that.byNowParams.itemCount = that.measurementJson.minSaleCount;
          that.setData({
            byNowParams: that.byNowParams
          });
          that.setData({
            minCount: that.byNowParams.itemCount
          });
        },
        fail: function (res) {
          console.log("fail");
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },

    /* 初始化 选规格 */
    chooseMeasureItem: function (event) {
      console.log('----------初始化规格参数-----------', event);
      let productData = this.productData;
      let focusProduct = productData;
      let selectTypeData = [];

      for (let i = 0; i < focusProduct.measures.length; i++) {
        focusProduct.measures[i].checkedMeasureItem = 0; //初始化选择的数据

        let param = {};
        let selectTypeDataItem = {};
        param.name = focusProduct.measures[i].name;
        param.value = focusProduct.measures[i].productAssignMeasure[0].id;
        selectTypeDataItem.type = focusProduct.measures[i].name;
        selectTypeDataItem.value = focusProduct.measures[i].productAssignMeasure[0].measureName;
        console.log('=====param=====', param);
        this.MeasureParams.push(param);
        selectTypeData.push(selectTypeDataItem);
      }

      this.selectTypeData = selectTypeData;
      console.log('====that.data.selectTypeData======', this.selectTypeData);
      this.setData({
        productData: focusProduct
      });
      console.log('===MeasureParams====', this.MeasureParams);
      this.get_measure_cartesionFun();
    },
    //选择规格小巷的---显示
    radioChange: function (e) {
      let that = this;
      let flag = false;
      console.log("====radioChange=====", e);
      console.log('====that.data.selectTypeData======', that.selectTypeData);

      if (that.selectTypeData) {
        console.log('1111111');

        for (let i = 0; i < that.selectTypeData.length; i++) {
          if (e.currentTarget.dataset.type == that.selectTypeData[i].type) {
            that.selectTypeData.splice(i, 1, e.currentTarget.dataset);
            flag = true;
          }
        }

        if (!flag) {
          that.selectTypeData.splice(that.selectTypeData.length, 1, e.currentTarget.dataset);
          flag = false;
        }
      } else {
        console.log('222222');
        that.selectTypeData = [];
        that.selectTypeData.splice(0, 1, e.currentTarget.dataset);
        that.setData({
          selectTypeData: that.selectTypeData
        });
      }

      console.log('====that.data.selectTypeData======', that.selectTypeData);
      let index = e.currentTarget.dataset.index;
      let indexJson = getApp().globalData.getSpaceStr(index, '-'); //console.log(indexJson)

      let focusItem = that.productData;
      focusItem.measures[indexJson.str1].checkedMeasureItem = indexJson.str2;
      that.setData({
        productData: focusItem
      });
    },
    //选择规格小巷---获取数据
    chooseMeasure: function (e) {
      console.log(e.detail.value);
      let chooseMeasureJson = getApp().globalData.getSpaceStr(e.detail.value, '-');
      console.log(chooseMeasureJson);

      for (let i = 0; i < this.MeasureParams.length; i++) {
        if (this.MeasureParams[i].name == chooseMeasureJson.str1) {
          this.MeasureParams[i].value = chooseMeasureJson.str2;
        }
      }

      this.get_measure_cartesionFun();
    },
    closeGuigeZhezhao: function () {
      this.setData({
        showGuigeType: false
      });
      this.MeasureParams = [];
    },
    // 获取二维码
    getQrCode: function () {
      let userId = "";

      if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
        userId = 'MINI_PLATFORM_USER_ID_' + getApp().globalData.loginUser.platformUser.id;
      } // console.log("app.loginUser.platformUser", app.loginUser.platformUser.id)
      // path=pageTab%2findex%2findex%3fAPPLY_SERVER_CHANNEL_CODE%3d'


      let postParam = {};
      postParam.SHARE_PRODUCT_DETAIL_PAGE = this.proId;
      postParam.scene = userId; // 上面是需要的参数下面的url

      console.log('====pp======', "/super_shop_manager_get_mini_code.html?mini=1&path=pageTab%2findex%2findex%3fSHARE_PRODUCT_DETAIL_PAGE%3d" + this.proId + "%26scene%3d" + userId);
      var customIndex = getApp().globalData.AddClientUrl("/super_shop_manager_get_mini_code.html?mini=1&path=pageTab%2findex%2findex%3fSHARE_PRODUCT_DETAIL_PAGE%3d" + this.proId + "%26scene%3d" + userId, postParam, 'get', '1');
      var result = customIndex.url.split("?");
      customIndex.url = result[0] + "?" + result[1];
      console.log("customIndex", customIndex.url, result[0]);
      var that = this;
      that.setData({
        qrCodeUrl: customIndex.url
      });
    },
    // 定位
    clickCatch: function (e) {
      console.log(this.productData.productInfo);
      let latitude = this.productData.productInfo.latitude;
      let longitude = this.productData.productInfo.longitude;
      let name = this.productData.productInfo.name;
      let address = this.productData.productInfo.location;
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        scale: 12,
        name: name,
        address: address
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>